/*
 * Copyright (C) 2001-2005 Pleasant nightmare studio
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package skunkworks;

import com.jme.app.SimpleGame;
import com.jme.renderer.ColorRGBA;
import com.jmex.bui.BComponent;
import com.jmex.bui.BStyleSheet;
import com.jmex.bui.BWindow;
import com.jmex.bui.PolledRootNode;
import com.jmex.bui.background.TintedBackground;
import com.jmex.bui.layout.HGroupLayout;
import com.jmex.bui.layout.VGroupLayout;
import com.jmex.bui.provider.DefaultResourceProvider;
import com.jmex.bui.util.Dimension;
import org.pleasantnightmare.gblade.data.ComponentData;
import org.pleasantnightmare.gblade.data.ComponentType;
import org.pleasantnightmare.gblade.data.PropertyData;
import org.pleasantnightmare.gblade.io.Data2GBui;

import java.io.InputStreamReader;

/**
 * Test that XML, data and BUI are on same level ;-)
 *
 * @author deus
 * @version 1.0
 * @since Sep 9, 2009 12:44:09 PM
 */
public class IOTest extends SimpleGame {
  private BStyleSheet styleSheet;
  private PolledRootNode bRootNode;

  @Override protected void simpleInitGame() {
    ComponentData basicData = buildWindowWithFewComponents();
    exportToXml(basicData);

    BComponent component = Data2GBui.buildBui(basicData);

    // Setup BUI framework
    bRootNode = new PolledRootNode(timer, input);
    styleSheet = new BStyleSheet(
        new InputStreamReader(ClassLoader.getSystemResourceAsStream("/stylesheet.bss")),
        new DefaultResourceProvider());
//    bRootNode.addWindow((BWindow) component);
    bRootNode.addWindow(testWindow());

    rootNode.attachChild(bRootNode);
  }

  private BWindow testWindow() {
    BWindow window = new BWindow("Window", styleSheet, new VGroupLayout());
    window.setSize(400, 300);
    window.center();
    window.setBackground(0, new TintedBackground(ColorRGBA.red));
    return window;
  }

  private ComponentData buildWindowWithFewComponents() {
    ComponentData window = new ComponentData(ComponentType.WINDOW, "main-window");
    window.addPropertyData("title", "Hello world");
    window.addPropertyData("preferredSize", new Dimension(400, 300));
    window.addPropertyData("layoutManager", HGroupLayout.class);

    PropertyData backgroundProperty = new PropertyData("background", TintedBackground.class);
    backgroundProperty.addPropertyData("color", ColorRGBA.red);
    window.addPropertyData(backgroundProperty);

    // TODO add containers and components
    return window;
  }

  private void exportToXml(ComponentData basicData) {
    // TODO implement me
  }

  public static void main(String[] args) {
    IOTest ioTest = new IOTest();
    ioTest.setConfigShowMode(ConfigShowMode.ShowIfNoConfig);
    ioTest.start();
  }
}
